package com.tianyuan.dplrf.ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatButton;
import androidx.appcompat.widget.AppCompatCheckBox;
import androidx.appcompat.widget.AppCompatTextView;

import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TableRow;
import android.widget.TextView;

import com.tianyuan.dplrf.R;
import com.tianyuan.dplrf.app.AppActivity;
import com.tianyuan.dplrf.ui.catogray.IntentKeySetting;

import java.util.ArrayList;
import java.util.List;

public class PayLandActivity extends AppActivity implements View.OnClickListener {

    private ImageView img_land_back;
    private TextView tv_title;
    private TextView tv_zfje;
    private TextView tv_zfjesj;
    private AppCompatTextView tv_pay_mode1;
    private AppCompatCheckBox checkbox1;
    private TableRow tab1;
    private AppCompatTextView tv_pay_mode2;
    private AppCompatCheckBox checkbox2;
    private TableRow tab2;
    private AppCompatButton btn_zf;
    private LinearLayout linearcontent;

    private List<CheckBox> zfmodeList;

    private String act;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_pay_land;
    }

    @Override
    protected void initView() {

        img_land_back = findViewById(R.id.img_land_back);
        tv_title = findViewById(R.id.tv_title);
        tv_zfje = findViewById(R.id.tv_zfje);
        tv_zfjesj = findViewById(R.id.tv_zfjesj);
        tv_pay_mode1 = findViewById(R.id.tv_pay_mode1);
        checkbox1 = findViewById(R.id.checkbox1);
        tab1 = findViewById(R.id.tab1);
        tv_pay_mode2 = findViewById(R.id.tv_pay_mode2);
        checkbox2 = findViewById(R.id.checkbox2);
        tab2 = findViewById(R.id.tab2);
        btn_zf = findViewById(R.id.btn_zf);
        linearcontent = findViewById(R.id.linearcontent);
        img_land_back.setOnClickListener(this);
        checkbox1.setOnClickListener(this);
        tab1.setOnClickListener(this);
        checkbox2.setOnClickListener(this);
        tab2.setOnClickListener(this);
        btn_zf.setOnClickListener(this);

        tv_title.setVisibility(View.GONE);
        textdrawableSetting(tv_pay_mode1,R.drawable.ic_user,18, Gravity.LEFT);
        textdrawableSetting(tv_pay_mode2,R.drawable.ic_user,18, Gravity.LEFT);
    }

    @Override
    protected void initData() {

        act = getIntent().getStringExtra(IntentKeySetting.KEYACT);

        //选择一种支付方式
        chooseCheckMode(0);

    }

    private void chooseCheckMode(int mode) {
        if (zfmodeList == null){
            zfmodeList = new ArrayList<>();
            zfmodeList.add(checkbox1);
            zfmodeList.add(checkbox2);
        }
        for (int a = 0;a < zfmodeList.size();a++){
            if (mode == a){
                zfmodeList.get(a).setChecked(true);
            }else {
                zfmodeList.get(a).setChecked(false);
            }
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_land_back:
                finish();
                break;
            case R.id.checkbox1:
            case R.id.tab1:
                chooseCheckMode(0);
                break;
            case R.id.checkbox2:
            case R.id.tab2:
                chooseCheckMode(1);
                break;
            case R.id.btn_zf:
                toast(getResources().getString(R.string.srt_zfcg));
                if (act.equals(ChoosezdpageActivity.class.getSimpleName())){
                    startActivity(MinencAct.class);
                }
                finish();
                break;
        }
    }
}